package com.his.controller;

import com.his.entity.MedicinePrescriptionRecord;
import com.his.entity.ResponseResult;
import com.his.service.IPharmacyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/pharmacy")
@Tag(name = "药房工作台模块接口")
public class PharmacyController {

    @Resource
    private IPharmacyService pharmacyService;

    @PostMapping("fresh")
    @Operation(summary = "拉取已发药和未发药的列表")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，拉取列表成功和已发药数组及未发药数组"),
            @ApiResponse(responseCode = "400", description = "返回400，拉去列表失败"),
    })
    public ResponseResult fresh() {
        return pharmacyService.refresh();
    }

    @PostMapping("distribute-medicine")
    @Operation(summary = "根据药品处方id发药", description = "处方id是必须参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，发药成功"),
            @ApiResponse(responseCode = "400", description = "返回400，发药失败"),
    })
    public ResponseResult distributeMedicine(@RequestBody MedicinePrescriptionRecord medicinePrescriptionRecord) {
        return pharmacyService.distributeMedicine(medicinePrescriptionRecord);
    }

    @PostMapping("return-medicine")
    @Operation(summary = "根据药品处方id退药", description = "处方id是必须参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，退药成功"),
            @ApiResponse(responseCode = "400", description = "返回400，退药失败"),
    })
    public ResponseResult returnMedicine(@RequestBody MedicinePrescriptionRecord medicinePrescriptionRecord) {
        return pharmacyService.returnMedicine(medicinePrescriptionRecord);
    }
}
